package web

import (
	"time"

	"gitee.com/xgotool/sqlite-logs-more/service/rootdb"
	"gitee.com/xiaoyutab/xgotool/xgin"
	"github.com/gin-gonic/gin"
)

// 设备心跳维持
//
//	POST	dervice.info.hart
func DerviceInfoHart(c *gin.Context) *xgin.Response {
	m := map[string]string{}
	if err := xgin.Bind(c, &m); err != nil {
		return xgin.Resp().Error(err)
	}
	// 获取设备详情信息
	der, err := rootdb.DerviceInfoByMac(m, c.ClientIP())
	if err != nil {
		return xgin.Resp().Error(err)
	}
	der.InLine = 1
	der.LastHart = time.Now().Unix()
	err = rootdb.DerviceSet(der)
	if err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().SuccessAny(der)
}
